package pt.ua.miect.sd.simuladorpesca.entities;

import  org.apache.log4j.Logger;
import pt.ua.miect.sd.simuladorpesca.SimulationConfig;

public class FishSchool extends MapEntity {

    
    public enum FishSchoolState {

        SPAWNING_AREA, FEEDING_AREA, TRAPPED_IN_NET, MOVING_TO_SPAWNING_AREA
    }
    private long fishPopulation;
    private FishSchoolState status;

    public FishSchool(String fishId, MapPosition pos) {
        super(fishId);
        this.fishPopulation = SimulationConfig.INITIAL_FISH_COUNT;
        setMapPosition(pos);
        status = FishSchoolState.SPAWNING_AREA; //simulation has not started, FEEDING_AREA is default state
    }

    /**
     * @return the status
     */
    public FishSchoolState getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public synchronized void setStatus(FishSchoolState status) {
        this.status = status;
    }

    /**
     * @return the fishPopulation
     */
    public long getFishPopulation() {
        return fishPopulation;
    }

    /**
     * @param fishPopulation the fishPopulation to set
     */
    public void setFishPopulation(long fishPopulation) {
        this.fishPopulation = fishPopulation;
    }
    


    /**
     * Implements Fish Cluster Growth
     * @param fishCount the fishCount to set
     */
    public void growFish() {
       long newpop = (long)(this.fishPopulation * (1 + SimulationConfig.GROWTH_RATE - SimulationConfig.ECOSYSTEM_COEFICIENT * this.fishPopulation  ));
       long growth = newpop - fishPopulation;
        setFishPopulation(newpop);
       //population has to be always at least 1
        if (this.fishPopulation <= 0)
        {
            this.setFishPopulation(1);
        }
       if(growth > 0){
       Logger.getRootLogger().info(this.getId()+" has grown by "+growth+ " Fish, they are now "+ fishPopulation+"!");

        }
 else
       {
           Logger.getRootLogger().info(this.getId()+ " can not grow anymore! they will start look for new feeding areas");
           this.setStatus(FishSchoolState.FEEDING_AREA);
        }
 }





}
